package cn.itcast.CompletableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author : 叶荻风
 * @create : 2024/8/9 17:30
 */
public class CompletableFutureTest {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(5);
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("执行step 1");
            return "step1 result";
        },executor);
        CompletableFuture<String> f2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("执行step 2");
            return "step2 result";
        }, executor);

        f1.thenCombine(f2,(r1,r2)->{
            System.out.println(r1+" "+r2);
            System.out.println("执行step3");
            return "step3 result";
        }).thenAccept(r3->{
            System.out.println(r3);
        });
    }
}
